<template>
  <div class="container">
    <div class="cash-coin-bar text-align-c" :style="'background-color:' + globalStyle.color2 + ';'">
      <div class="font-18 pad-t-20">可提现金额</div>
      <div class="font-30 font-w">￥{{ cashApply.availableAmount }}</div>
    </div>
    <div class="mar-15 pad-t-10" @click="confirm">
      <div class="get-form-id">
        <get-form-id :width="330" :height="50"></get-form-id>
      </div>
      <button class="cash-btn">确认提现</button>
    </div>
    <div class="mar-20 font-color-8 font-14">
      <div class="font-w">提现需知：</div>
      <div class="mar-t-5">1、申请提现后，1-3个工作日到账。</div>
      <div class="mar-t-5">2、可提现金额需大于{{ cashCount }}元，才可提现。</div>
      <div class="mar-t-5">3、店铺每笔收入扣千分之六的手续费。</div>
    </div>
    <div class="div-pop" v-if="question">
      <div class="pad-l-30 pad-r-30">
        <div class="panel pad-30">
          <div>
            您的店铺收入，需在订单状态完成后的24小时后才可以转为可提现收入
          </div>
          <div class="pad-t-20 pad-l-20 pad-r-20">
            <button class="mini-btn" @click="question=false">我知道了</button>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
  import {
    statTakeOutByMemberId,
    doApplyTakeOut
  } from '@/api/personal'
  import { getMemberInfo } from '@/api/home'
  import GetFormId from '@/components/GetFormId'

  export default {
    components: { GetFormId },
    data() {
      return {
        cashApply: {},
        question: false,
        memberInfo: {},
        globalStyle: {},
        cashCount: 10
      }
    },
    onShow() {
      let getAppInfo = this.$pt.getStorageSync('appInfo')
      this.globalStyle = getAppInfo.style
      this.statTakeOutByMemberId()
    },
    methods: {
      statTakeOutByMemberId() {
        getMemberInfo(this.getCustomerId).then((response) => {
          if (response.isError) return
          this.memberInfo = response.data
          statTakeOutByMemberId({
            memberId: this.getCustomerId
          }).then((response) => {
            if (response.isError) return
            this.cashApply = response.data
          }).catch(() => {
          })
        }).catch(() => {
        })
      },
      confirm() {
        // 易宝提现需完善信息 yeepayAuthStatus !== 2
        if (this.memberInfo.yeepayAuthStatus !== 2 && this.getPayMethod !== 2) {
          const that = this
          this.$pt.showModal({
            content: '请先完善银行卡信息',
            confirmText: '立即完善',
            success(res) {
              if (res.confirm) {
                that.$pt.navigateTo({url: '/pages/personal/verify-auth/main?pageFrom=list'})
              } else if (res.cancel) {
                console.log('用户取消')
              }
            }
          })
          return
        }
        // 通联提现需完善信息 allinPayAuthStatus !== 2
        if (this.memberInfo.allinPayAuthStatus !== 2 && this.getPayMethod === 2) {
          const that = this
          this.$pt.showModal({
            content: '请先完善银行卡信息',
            confirmText: '立即完善',
            success(res) {
              if (res.confirm) {
                that.$pt.navigateTo({url: '/pages/personal/verify-auth/allin-auth/main?pageFrom=list'})
              } else if (res.cancel) {
                console.log('用户取消')
              }
            }
          })
          return
        }
        if (this.cashApply.availableAmount * 1 < this.cashCount) {
          this.$utils.showToast({ title: '可提现金额不足' + this.cashCount + '元，暂不能提现' })
          return
        }
        doApplyTakeOut({
          applyUserId: this.getCustomerId
        }).then((response) => {
          if (response.isError) return
          this.$utils.showToast({ title: '申请成功' })
          setTimeout(() => {
            this.$pt.redirectTo({url: '/pages/personal/wallet/cash-progress/main'})
          }, 500)
        }).catch(() => {
        })
      }
    }
  }
</script>

<style lang="less" scoped>
.cash-coin-bar{
  height: 130px;
  // background: #FFE200;
}
  .card-num {
    margin-top: -70px;
    padding-left: 135px;
  }

  .cash-item {
    margin-top: 60px;
  }

  .mid-border {
    height: 60px;
  }
.cash-btn{
  width: 345px;
  height: 50px;
  padding: 0;
  border-radius: 25px;
  background: #FFE200;
  &::after{
    border: unset;
  }
}
  .get-form-id {
    position: absolute;
    width:345px;
    height:50px;
    z-index: 999;
    border-radius: 25px;
  }
</style>
